class Eventbus {
  constructor() {
    this.eventBus = {}
  }

  on(type, callback) {
    if(this.eventBus[type]){
      this.eventBus[type].push(callback)
    }else {
      this.eventBus[type]=[]
      this.eventBus[type].push(callback)
    }
  }
  emit(type,value){
    this.eventBus[type].forEach(fn=>{
      fn(value)
    })
  }
}

const eventBus = new Eventbus()

eventBus.on('add', value => {
  document.querySelector('.value1').innerText=parseInt(document.querySelector('.value1').innerText)+value
})
eventBus.on('add',value=>{
  document.querySelector('.value2').innerText=parseInt(document.querySelector('.value2').innerText)+10+value
})



window.onload=function (){
  document.querySelector('#lyw').onclick = function () {
    eventBus.emit('add',1)
  }
  document.querySelector('#ljj').onclick=function (){
    eventBus.emit('add',2)
  }
}

